<!--
 * @autoAdd: zhuxiaobao
-->
<!--
 * @autoAdd: zhuxiaobao
-->
<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="12">
            <a-form-item label="交易号">
              <j-input placeholder="输入交易号模糊查询" v-model="queryParam.transactionNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item label="需求名称">
              <j-input placeholder="输入需求名称模糊查询" v-model="queryParam.demandName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
              >重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- 高级查询区域 -->
      <j-super-query
        :fieldList="superFieldList"
        ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"
      ></j-super-query>
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt
            style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)"
          >下载</a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-popconfirm title="确定投产吗?" @confirm="() => handleInto(record)" v-if="record.status==='05'">
            <a>投产</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <!-- 编辑弹框
    <psdb-demand-modal ref="modalForm" @ok="modalFormOk"></psdb-demand-modal>
    任务分配弹窗-->
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { loadCategoryData } from '@/api/api'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { getAction } from '@/api/manage'

export default {
  name: 'PsdbDemandList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  data() {
    return {
      description: '需求管理管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '交易号',
          align: "center",
          dataIndex: 'transactionNo'
        },
        {
          title: '需求名称',
          align: "center",
          dataIndex: 'demandName'
        },
        {
          title: '需求联系人',
          align: "center",
          dataIndex: 'demandContacts'
        },
        {
          title: '业务部门',
          align: "center",
          dataIndex: 'businessUnit'
        },
        {
          title: '调用方系统',
          align: "center",
          dataIndex: 'callerSys',
          customRender: (text) => {
            return text ? filterMultiDictText(this.dictOptions['callerSys'], text) : ''
            }
        },
        {
          title: '调用方负责人',
          align: "center",
          dataIndex: 'cellerUser'
        },
        {
          title: '需求来源',
          align: "center",
          dataIndex: 'demandSource'
        },
        {
          title: '对接系统',
          align: "center",
          dataIndex: 'dockingSys',
          customRender: (text) => (text ? filterMultiDictText(this.dictOptions['dockingSys'], text) : '')
        },
        {
          title: '期望上线时间',
          align: "center",
          dataIndex: 'expectTime',
          customRender: function (text) {
            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: 'oa联系单号',
          align: "center",
          dataIndex: 'oaNo'
        },
        {
          title: '需求说明',
          align: "center",
          dataIndex: 'demandDes'
        },
        {
          title: '需求状态',
          align: "center",
          dataIndex: 'status_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 80,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/dev/manager/list",
        statusEdit: '/demand/psdbDemand/status_edit'
      },
      dictOptions: {},
      superFieldList: [],
      disableMixinCreated: true,
    }
  },
  created() {
    this.filters.status = "05"
    // 新增/修改 成功时，重载列表
    this.loadData();
    //清空列表选中
    this.initDictConfig();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    initDictConfig() {
      loadCategoryData({ code: '' }).then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'callerSys', res.result)
        }
      })
      loadCategoryData({ code: '' }).then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'dockingSys', res.result)
        }
      })
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'transactionNo', text: '交易号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'demandName', text: '需求名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'demandContacts', text: '需求联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'businessUnit', text: '业务部门', dictCode: '' })
      fieldList.push({ type: 'string', value: 'callerSys', text: '调用方系统' })
      fieldList.push({ type: 'string', value: 'cellerUser', text: '调用方负责人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'demandSource', text: '需求来源', dictCode: '' })
      fieldList.push({ type: 'string', value: 'dockingSys', text: '对接系统' })
      fieldList.push({ type: 'date', value: 'expectTime', text: '期望上线时间' })
      fieldList.push({ type: 'string', value: 'oaNo', text: 'oa联系单号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'demandDes', text: '需求说明', dictCode: '' })
      fieldList.push({ type: 'string', value: 'status', text: '需求状态', dictCode: 'demand_status' })
      this.superFieldList = fieldList
    },
    taskFormOk() {
      // 新增/修改 成功时，重载列表
      this.loadData();
      //清空列表选中
      this.onClearSelected()
    },
    handleInto(data) {
      getAction(this.url.statusEdit, { id: data.id, status: '06' }).then(res => {
        this.$message.success(res.message)
        this.taskFormOk()
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>